package com.gotrade.springbootexceptiondemo.exception;

import com.gotrade.springbootexceptiondemo.common.enums.ResultCode;
import lombok.Getter;

/**
 * @author jason.tang
 * @create 2019/4/28
 * @description API 自定义异常
 */

@Getter
public class ApiException extends RuntimeException {
    /** 错误码 */
    private ResultCode resultCode;

    /** 携带数据 */
    private Object data;

    /**
     * 抛错误码异常
     * @param resultCode
     */
    public ApiException(ResultCode resultCode) {
        super(resultCode.msg());
        this.resultCode = resultCode;
    }

    /**
     * 抛自定义信息异常
     * @param message
     */
    public ApiException(String message) {
        super(message);
    }

    /**
     * 抛错误码异常。并且携带相关数据信息
     * @param resultCode
     * @param data
     */
    public ApiException(ResultCode resultCode, Object data) {
        super(resultCode.msg());
        this.resultCode = resultCode;
        this.data = data;
    }

    /**
     * 抛异常，并传入异常
     * @param cause
     */
    public ApiException(Throwable cause) {
        super(cause);
    }

    /**
     * 抛异常，自定义信息并传入异常
     * @param message
     * @param cause
     */
    public ApiException(String message, Throwable cause) {
        super(message, cause);
    }
}
